//
//  AddressView.swift
//  Box
//
//  Created by mn on 2025/4/1.
//

import UIKit

class AddressView: UIView{

    let locationImageView = UIImageView(image: UIImage.location)
    let lineImageView = UIImageView(image: UIImage.addressLine)
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.textColor = .fromHex("#001C00")
        label.font = UIFont.systemFont(ofSize: 15,weight: .heavy)
        return label
    }()
    lazy var phoneLabel: UILabel = {
        let label = UILabel()
        label.textColor = .fromHex("#001C00")
        label.font = UIFont.systemFont(ofSize: 15,weight: .heavy)
        return label
    }()
    lazy var addressLabel: UILabel = {
        let label = UILabel()
        label.textColor = .fromHex("#7D7D7D")
        label.font = UIFont.systemFont(ofSize: 12)
        return label
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupUI()
    }
    func setupUI() {
        backgroundColor = .white
        [nameLabel,phoneLabel,addressLabel,locationImageView,lineImageView].forEach {
            addSubview($0)
        }
        locationImageView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.top.equalToSuperview().offset(12)
            make.width.height.equalTo(20)
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(locationImageView.snp.right).offset(12)
            make.top.equalTo(locationImageView.snp.top)
        }
        phoneLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel.snp.right).offset(21)
            make.centerY.equalTo(nameLabel.snp.centerY)
        }
        addressLabel.snp.makeConstraints { make in
            make.left.equalTo(locationImageView.snp.right).offset(12)
            make.top.equalTo(nameLabel.snp.bottom).offset(12)
        }
        lineImageView.snp.makeConstraints { make in
            make.top.equalTo(addressLabel.snp.bottom).offset(10)
            make.left.right.bottom.equalToSuperview()
            make.height.greaterThanOrEqualTo(6.5)
        }
    }
    var data: AddressData!{
        didSet{
            nameLabel.text = data.name
            phoneLabel.text = data.mobile
            addressLabel.text = data.addressPathDes + data.detailAddress
        }
    }
}
